package com.heima.schedule.feign;

import com.heima.apis.schedule.IScheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.scedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ScheduleClient implements IScheduleClient {
    @Autowired
    private TaskService taskService;

    /**
     * 创建延迟任务所需要的接口
     *
     * @param task
     * @return
     */
    @PostMapping("/api/vi/task/add")
    public ResponseResult addtask(@RequestBody Task task) {
        return ResponseResult.okResult(taskService.addtask(task));
    }

    /**
     * 删除任务表,更新log表,删除redis中的zset 或者list
     * 取消任务
     *
     * @param taskId
     * @return
     */
    @GetMapping("/api/vi/task/{taskId}")
    public ResponseResult cache(@PathVariable("taskId") long taskId) {
        return ResponseResult.okResult(taskService.cache(taskId));
    }

    /**
     * 拉取任务
     *
     * @param type
     * @param priority
     * @return
     */
    @GetMapping("api/vi/task/{type}/{priority}")
    public ResponseResult poll(@PathVariable("type") int type, @PathVariable("priority") int priority) {
        return ResponseResult.okResult(taskService.poll(type,priority));
    }
}
